<?php if(!defined('WDK_PATH')) exit('No direct script access allowed');
/**
 * @since 2011. 9. 30
 * @author kinuz
 */
class Hp_AdminSession implements ArrayAccess
{
	protected
		/******************************************************/
		//	
		/******************************************************/
		$id				= '',
		$user_seq		= 0,
		$user_login_id	= '',
		$user_name		= '',
		$user_nick		= '';
	
	//--------------------------------------------------------------------------------------------//
	//	functions to implemet for ArrayAccess
	//--------------------------------------------------------------------------------------------//
	public final function offsetSet($offset, $value) {$this->{$offset} = $value;}
	public final function offsetExists($offset) {return isset($this->{$offset});}
	public final function offsetUnset($offset) {unset($this->{$offset});}
	public final function offsetGet($offset) {return isset($this->{$offset}) ? $this->{$offset} : null;}
	//--------------------------------------------------------------------------------------------//
	/**
	 * 	생성자
	 * @since 2011. 9. 30
	 * @author kinuz
	 */
	function __construct()
	{
		session_start();
		$this->id = session_id();
		if($_SESSION
		&& array_key_exists('_ADMIN_', $_SESSION)
		&& is_array($_SESSION['_ADMIN_'])
		&& empty($_SESSION['_ADMIN_']) == false)
		{
			foreach($_SESSION['_ADMIN_'] as $k=>$v)	$this->{$k} = $v;
		}
	}
	
	public function set($name='', $value='')
	{
		if(array_key_exists('_ADMIN_', $_SESSION) == false)
		{
			$_SESSION['_ADMIN_'] = array();
		}
		if($value === '')
		{
			unset($_SESSION['_ADMIN_'][$name]);
		}
		else
		{
			$_SESSION['_ADMIN_'][$name] = $value;
		}
	}
	
	public function destroy()
	{
		unset($_SESSION['_ADMIN_']);
	}
	
	public function isLogin()
	{
		return $this->user_seq > 0;
	}
}